package com.example.springbootdynamicdatasource.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.dynamic.datasource.annotation.Master;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.springbootdynamicdatasource.entity.User;
import com.example.springbootdynamicdatasource.mapper.UserMapper;
import com.example.springbootdynamicdatasource.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author vicente
 * @since 2022-01-20
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    //@DS("db1")
    @Master
    public List<User> getUserList() {
        //QueryWrapper<User> last = new QueryWrapper<User>().eq("name", "Tom").eq("age", "28").last("limit 1");
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        List<User> userList = userMapper.selectList(userQueryWrapper);
        for (User user: userList){
            System.out.println(JSON.toJSONString(user));
        }
        return userList;
    }

}
